<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称">
              <j-dict-select-tag v-model="queryParam.customerId" placeholder="请选择客户"
                                 dictCode="zcgl_customer_info,name,id"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="联系电话">
              <a-input placeholder="请输入联系电话" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="身份证/信用代码">
              <a-input placeholder="请输入身份证/信用代码" v-model="queryParam.code"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="管理单位">
                <j-dict-select-tag v-model="queryParam.companyId" placeholder="请选择管理单位"
                                   dictCode="sys_depart,depart_name,id"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="出租方公司名称">
                <j-dict-select-tag v-model="queryParam.rentCompanyId" placeholder="请选择管理单位"
                                   dictCode="sys_depart,depart_name,id"/>
              </a-form-item>
            </a-col>
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="开始统计时间">-->
<!--                <j-dict-select-tag v-model="queryParam.customerId" placeholder="请选择所属公司"-->
<!--                                   dictCode="zcgl_customer_info,CONCAT_WS( ' ', `name`, phone ),id"/>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="结束统计时间">-->
<!--                <j-dict-select-tag v-model="queryParam.regionId" placeholder="请选择所属公司"-->
<!--                                   dictCode="zcgl_region,region_name,id"/>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-has="'assetLedger:export'" type="primary" icon="download" @click="handleExportXls('资产台账统计')">导出
      </a-button>
    </div>


    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        :scroll="{ x: 2000, y: screenHeight }"
        rowKey="id"
        class="j-table-force-wrap"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">
        <span slot="serial" slot-scope="text,record,index">{{index + 1}}</span>
        <template slot="footer" slot-scope="currentPageData">
          <a-table
            bordered
            class="footerTable"
            size="small"
            :columns="footColumns"
            :dataSource="footerData"
            :scroll="{ x: 2000, y: screenHeight }"
            :pagination="false"
            :showHeader="false">
            <span slot="serial">合计</span>
          </a-table>
        </template>
      </a-table>
    </div>

    <assetInfo-modal ref="modalForm" @ok="modalFormOk"></assetInfo-modal>
    <assetInfoDisposal-modal ref="modalDisposalForm" @ok="modalDisposalOk"></assetInfoDisposal-modal>
  </a-card>
</template>

<script>
import { getAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import AssetInfoModal from '../modules/AssetInfoModal'
import AssetInfoDisposalModal from '../modules/AssetInfoDisposalModal'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JInput from '@/components/jeecg/JInput'
import JDate from '@/components/jeecg/JDate.vue'
import '@/assets/less/TableExpand.less'

export default {
  name: 'PersonalOnlinePlatformPayment',
  mixins: [JeecgListMixin],
  components: {
    JDate,
    JInput,
    JDictSelectTag,
    AssetInfoDisposalModal,
    AssetInfoModal
  },
  data () {
    return {
      description: '个人在线支付',
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'rowIndex',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          fixed: 'left',
          customRender: (text, record, index) =>
            `${(this.ipagination.current - 1) * this.ipagination.pageSize + index + 1}`
        },
        {
          title: '客户名称',
          align: 'center',
          dataIndex: 'customerId_dictText'
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'phone'
        },
        {
          title: '身份证/信用代码',
          align: 'center',
          dataIndex: 'code'
        },
        {
          title: '账单编号',
          align: 'center',
          dataIndex: 'payablesNo'
        },
        {
          title: '合同编码',
          align: 'center',
          dataIndex: 'leaseContractId_dictText'
        },
        {
          title: '管理单位',
          align: 'center',
          dataIndex: 'companyId_dictText'
        },
        {
          title: '出租方公司名称',
          align: 'center',
          dataIndex: 'rentCompanyId_dictText'
        },
        {
          title: '入账账户',
          align: 'center',
          dataIndex: 'accountNo'
        },
        {
          title: '应付金额',
          align: 'center',
          dataIndex: 'amountPayable'
        },
        {
          title: '实付金额',
          align: 'center',
          dataIndex: 'amountRealPay'
        },
        {
          title: '交易单号',
          align: 'center',
          dataIndex: 'tradeNo'
        },
        {
          title: '支付方式',
          align: 'center',
          dataIndex: 'payType_dictText'
        },
        {
          title: '时间戳',
          align: 'center',
          dataIndex: 'tradeDateTime'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        }
      ],
      footColumns:[],
      footerData: [{
        key:'1'
      }],
      url: {
        list: '/zcgl/statisticalReport/personalOnlinePlatformPayment',
        // exportXlsUrl: '/zcgl/statisticalReport/personalOnlinePlatformPayment/exportXls',
      },
      dictOptions: {}
    }
  },
  created () {
    this.footColumns.push({
      title: '序号',
      dataIndex: 'rowIndex',
      key: 'rowIndex',
      width: 60,
      align: 'center',
      fixed: 'left',
      customRender: (text, record, index) =>
        '合计'
    })
    this.columns.forEach(value => {
      if(value.title !== '序号'){
        this.footColumns.push(value)
      }
    })
  },
  mounted () {
    const dom = this.$refs.table.$el.querySelectorAll('.ant-table-body')[0]
    dom.addEventListener('scroll',()=>{
      this.$refs.table.$el.querySelectorAll('.ant-table-body')[1].scrollLeft = dom.scrollLeft
    },true)
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
    importXlsDictUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importXlsDictUrl}`
    }
  },
  methods: {
    loadData (arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams()//查询条件
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        console.log(this.url.list + ':')
        console.log(res)
        if (res.success) {
          this.dataSource = res.result.records
          this.ipagination.total = res.result.total

          let rentPrice =0;
          let monthlyRent=0;
          let cashDeposit=0;
          let worth=0;
          res.result.records.forEach(value=>{
            rentPrice +=value.rentPrice
            monthlyRent +=value.monthlyRent
            cashDeposit +=value.cashDeposit
            worth +=value.worth
          })
          this.footerData[0].rentPrice = rentPrice
          this.footerData[0].monthlyRent = monthlyRent
          this.footerData[0].cashDeposit = cashDeposit
          this.footerData[0].worth = worth
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    initDictConfig(){
      this.addColumns()
    },
    modalDisposalOk () {
      this.loadData()
    }

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style>
.ant-table-footer {
  padding: 0;
}

.footerTable .ant-table-body {
  margin: 0px !important;
}

.footerTable .ant-table-thead {
  display: none;
}

.ant-table-footer .ant-table-body {
  overflow-x: hidden !important;
}

.footerTable .ant-table-small .ant-table-bordered {
  border: 0px;
}

.footerTable .ant-table-small .ant-table-bordered .ant-table-footer {
  border: 0px;
}
</style>